package org.restorator.dao.implement;

import org.restorator.dao.base.OrderDao;
import org.restorator.entity.AnonymClientOrder;
import org.restorator.entity.Item;
import org.restorator.entity.Order;
import org.restorator.exception.DataStoreException;

import java.util.*;

public class OrderDaoMock implements OrderDao {

    HashMap<Integer, Order> map = new HashMap<>();

    public OrderDaoMock() {
        Order o1 = new AnonymClientOrder();
        o1.setOrderId(1);
//        o1.setOpenDate(new Date());
        o1.setItems(Collections.nCopies(3, new Item(1, "Old Beer", 32.2, "Beers", "Beer")));

        Order o2 = new AnonymClientOrder();
        o2.setOrderId(2);
//        o2.setOpenDate(new Date());
        o2.setItems(Collections.nCopies(3, new Item(1, "New Beer", 38.2, "Beers", "Beer")));

        map.put(1, o1);
        map.put(2, o2);
    }

    @Override
    public Order getOrdersByTableId(int id) {
        return map.get(id);
    }

    @Override
    public Order get(Integer integer) {
        return map.get(integer);  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public Order update(Order persistElement) {
        for (Integer integer : map.keySet()) {
            if(integer.equals(persistElement.getOrderId())) {
                map.put(persistElement.getOrderId(), persistElement);
            }
        }
        return persistElement;
    }

    @Override
    public void delete(Order deleted) {
        map.remove(deleted.getOrderId());
    }

    @Override
    public long count() {
        return 0;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public Integer save(Order persist, Object... addParams) throws DataStoreException {
        map.put(persist.getOrderId(), persist);

        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public List<Order> getAll() throws DataStoreException {

        return new ArrayList<>(map.values());  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public boolean exist(Integer integer) {
        return map.containsKey(integer);  //To change body of implemented methods use File | Settings | File Templates.
    }
}
